﻿using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
namespace Hotel.UserControls
{
    public partial class ReportControl : System.Web.UI.UserControl
    {
        public string ReportPath
        {
            get;
            set;
        }
        public string ReportParams
        {
            get;
            set;
        }
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void Refresh()
        {

            this.rptViewer.ServerReport.ReportServerUrl = new Uri(ConfigurationManager.AppSettings["ReportServer"]);
            this.rptViewer.ServerReport.ReportPath = ConfigurationManager.AppSettings["ReportServer"] + ReportPath;
            List<ReportParameter> paramList = new List<ReportParameter>();
            string[] DELIMITERS = { "||", "=" };
            string[] sParams = ReportParams.Split(DELIMITERS, StringSplitOptions.None);
            for (int i = 0; i < sParams.Length; i += 2)
            {
                ReportParameter pParam = null;

                if (sParams[i + 1].Contains(";"))
                {
                    pParam = new ReportParameter(sParams[i], sParams[i + 1].Split(';'), false);
                }

                paramList.Add(pParam);
            }
            this.rptViewer.ServerReport.SetParameters(paramList);
            this.rptViewer.ServerReport.Refresh();
        }
    }
}